home *** CD-ROM | disk | FTP | other *** search
- Path: ix.netcom.com!netnews
- From: regmia@ix.netcom.com
- Newsgroups: comp.lang.c++
- Subject: Re: A simple "find the bug" (please! I need help :)
- Date: Wed, 21 Feb 1996 06:32:23 GMT
- Organization: Netcom
- Message-ID: <4gee6a$et3@cloner3.netcom.com>
- References: <4gdr6n$6p0@guava.epix.net>
- NNTP-Posting-Host: ix-lv3-20.ix.netcom.com
- X-NETCOM-Date: Tue Feb 20 10:30:34 PM PST 1996
- X-Newsreader: Forte Free Agent 1.0.82
-
- If that is actually what your program looks like then the problem is
- simple.
-
- result is not global, result only has scope within the function
- getnums().
-
- define result along with num1 and num2 and everything should
- work. NOTE: I'm making an assumption about your return value for
- getnum() I hope you just forgot here.
-
-
- jgvd@epix.net (Jon) wrote:
-
- >I wrote this just now and it's telling me that when i try to cout the
- >result at the bottom, it is an undefined value even though I did return
- >the result var... See if you can help.
-
- >#include <iostream.h>
-
- >float num1;
- >float num2;
-
- >getnums () {
-
- >float result = num1 +num2;
-
- >cout << "What number?\n";
- >cin >> num1;
- >cout << "And?\n";
- >cin >> num2;
-
- >return result;
- >}
-
- >main (){
-
- >getnums ();
-
-
- >cout << result;
- >}
-
- > ^^^^^^ right there is the result i want printed but it does not
- >recognize it even though I did try to return the value in the function
- >getnums... am I missing something?
-
- >Jon
-
-
-
-